package com.wd.rim.fragment


import activity.ReleaseActivity
import activity.ZoneActivity
import android.content.Intent
import diolag.JoinActivity
import apdate.SquareApdate
import diolag.EditActivity
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import apdate.TalkApdate
import com.wd.common.base.BaseFragment
import com.wd.common.viewmodel.MyViewModel
import com.wd.rim.R
import com.wd.rim.databinding.FragmentSquareBinding

class SquareFragment : BaseFragment<FragmentSquareBinding>() {
    private val mviewmodel:MyViewModel by viewModels()
    private var apdate:SquareApdate?=null
    private var apdate1:TalkApdate?=null
    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentSquareBinding = FragmentSquareBinding.inflate(layoutInflater)

    override fun initData() {
        binding.modelY.setOnClickListener {
            val intent1 = Intent()
            context?.let { it1 -> intent1.setClass(it1, ZoneActivity::class.java) }
            startActivity(intent1)
        }
        binding.more.setOnClickListener {
            val joinactivity = context?.let { it1 -> JoinActivity(it1) }
            if (joinactivity != null) {
                joinactivity.show()
            }
        }
        binding.edit.setOnClickListener {
            val editActivity = context?.let { it1 -> EditActivity(it1) }
            if (editActivity != null) {
                editActivity.show()
            }
        }
        mviewmodel.getTalk()
        mviewmodel.talk.observe(this){
            apdate1=context?.let { it1->TalkApdate(it1,it) }
            binding.recyId2.layoutManager=LinearLayoutManager(context)
            binding.recyId2.adapter=apdate1
        }

        //初始化
        mviewmodel.getRecom(1,10)
        //RadioGroup选择改变
        binding.squareRg.apply {
            check(R.id.square_recommend)
            setOnCheckedChangeListener { radioGroup, i ->
                when(i){
                    //推荐
                    R.id.square_recommend->{
                        mviewmodel.getRecom(1,20)
                    }
                    R.id.square_follow->{
                        mviewmodel.getInterest(1,20)
                    }
                    R.id.square_newenergy->{
                        mviewmodel.getNew(1,20)
                    }
                }
            }
        }

        mviewmodel.Recom.observe(this){
            if (it.status.equals("110")){

                Toast.makeText(context,it.message,Toast.LENGTH_SHORT)

            }else{
                apdate=context?.let {it1-> SquareApdate(it1,it) }
                binding.recyId.layoutManager= LinearLayoutManager(context)
                binding.recyId.adapter=apdate
            }
        }


    }



}